/*
	Author: Raffia
	Email : zhaody901@126.com
	Easy  : window.scrollTo(0,0);
	@code : 
*/
(function($){
	$.fn.scrollToTop = function(options){
		var defaults = {
			scrollTop:300,
			fiTime:300 ,
			foTime:300 ,
			scrollTime:800,
			debug:false
		}
		var opts = $.extend(defaults, options);

		this.each(function(i,ele){
			var $this = $(ele);
			$this.hide();
			$(window).scroll(function(){
				if ($(window).scrollTop() > opts.scrollTop) {
					$this.fadeIn(opts.fiTime);
				} else {
					$this.fadeOut(opts.foTime);
				}
			});

			$this.bind('click',function(){
				var c = null;
				var b = $(window).scrollTop();
				if ($.browser.msie) {
					window.scrollTo(0, 0);
				} else {
					function a() {
						b = Math.floor(b / 2);
						window.scrollTo(0, b);
						if (b > 2) {
							c = setTimeout(a, 40)
						} else {
							window.scrollTo(0, 0);
							clearTimeout(c)
						}
					}
					a()
				}
			})

		})
		function debug(info) {
			if (opts.debug && typeof(window.console) != undefined) {
				console.log(info);
			} else if (opts.debug && typeof(window.console) == undefined) {
				alert(info);
			}
		}
	}
})(jQuery)
